package com.cy_02;


import java.io.File;
import java.util.Scanner;

//递归 ----计算文件的大小
public class Test3 {
    public static void main(String[] args) {

        System.out.println("请输入文件路径:");
            String path =new Scanner(System.in).nextLine();

            File dir =new File(path);

            long sum = sizeOf(dir);
        System.out.println("文件夹是:"+path+",总大小是:"+sum);
    }

    private static long sizeOf(File dir) {
        File [] a =dir.listFiles();
        long sum = 0;
        for(int i = 0 ;i<a.length;i++){
            if(a[i].isFile()){
                sum =sum+a[i].length();
            }else if(a[i].isDirectory()){
                sum= sum+sizeOf(a[i]);
            }
        }
       return sum;

    }
}
